package com.healthcare;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import webservices.HealthCareServerProxy;

/**
 * Servlet implementation class DoctorQues
 */
public class DoctorQues extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoctorQues() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String doctorid = request.getSession().getAttribute("doctorid").toString();
		System.out.println("doctorsids" +doctorid);
		String userid = request.getSession().getAttribute("userid").toString();
		System.out.println("doctorsids" +doctorid);
		String question = request.getParameter("question");
		String label = request.getParameter("label");
		DateFormat dateFormat = new SimpleDateFormat(
				"EEE, d MMM yyyy HH:mm:ss Z");
		Date date = new Date();
		HealthCareServerProxy proxy = new HealthCareServerProxy();
 String status= proxy.postQuesDoc(doctorid, label, question, userid, dateFormat.format(date));
	String staticStatus = "Post is added!!";
	request.setAttribute("docpostStatus", status);
	if (status.equals(staticStatus)) {
		// request.getSession().setAttribute("postStatus", status);
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("/ListPosts.jsp");

	
		System.out.println("after the insert");
	} else {

		RequestDispatcher dispatcher = request
				.getRequestDispatcher("/DocList.jsp");

	

	}
	return;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
		String post = request.getParameter("data");
		System.out.println(post);
		System.out.println("hi");
		int postId = Integer.parseInt(post);

		String status = "false";
			
				HealthCareServerProxy proxy = new HealthCareServerProxy();
				if(proxy.deleteDocPosts(postId));
				{
				RequestDispatcher dispatcher = request.getRequestDispatcher("/DocListPosts.jsp");
				
				status="done";
				request.setAttribute("status", status);
				
				dispatcher.forward(request, response);
				
				}

	}
}

	

